package com.happy3w.ssp.schoolmatehome.service.note;

import com.happy3w.ssp.schoolmatehome.entity.Note;
import com.happy3w.ssp.schoolmatehome.entity.NoteTag;
import com.happy3w.ssp.schoolmatehome.entity.User;
import lombok.*;

import java.util.Date;
import java.util.List;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class NoteDetail {
    private Long id;

    private Long ownerId;

    private String title;

    private String summary;
    private Boolean manualSummary;

    private String background;

    private String content;

    private String scope;

    private Long templateId;

    private List<NoteTag> tags;

    private Date createdAt;

    private Date updatedAt;

    public static NoteDetail of(Note note, User user, List<NoteTag> tags) {
        return NoteDetail.builder()
                .id(note.getId())
                .ownerId(user.getId())
                .title(note.getTitle())
                .summary(note.getSummary())
                .manualSummary(note.getManualSummary())
                .background(note.getBackground())
                .content(note.getContent())
                .scope(note.getScope())
                .templateId(note.getTemplateId())
                .tags(tags)
                .createdAt(note.getCreatedAt())
                .updatedAt(note.getUpdatedAt())
                .build();
    }

    public Note buildNote() {
        return Note.builder()
                .id(id == null || id == 0 ? null : id)
                .ownerId(ownerId)
                .title(title)
                .summary(summary)
                .manualSummary(manualSummary)
                .background(background)
                .content(content)
                .scope(scope)
                .templateId(templateId)
                .createdAt(createdAt)
                .updatedAt(updatedAt)
                .build();
    }
}
